#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>


int wordToNum(const std::string& word) {
    std::map<std::string, int> wordToNumber = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };
    return wordToNumber[word];
}


bool isPrime(int n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i += 6) {
        if (n % i == 0 || n % (i + 2) == 0) return false;
    }
    return true;
}


int closestPrime(int n) {
    int lower = n - 1;
    int upper = n + 1;
    while (true) {
        if (isPrime(lower)) return lower;
        if (isPrime(upper)) return upper;
        lower--;
        upper++;
    }
}

int main() {
    std::string input;
    std::getline(std::cin, input);


    std::vector<std::string> words;
    std::string word;
    for (char c : input) {
        if (c == ' ') {
            words.push_back(word);
            word.clear();
        } else {
            word += c;
        }
    }
    words.push_back(word); 

    
    if (words.size() != 3) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    
    int num = wordToNum(words[0]) * 100 + wordToNum(words[1]) * 10 + wordToNum(words[2]);

  
    if (num < 100 || num > 999) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

   
    int closest = closestPrime(num);

    
    std::cout << closest << std::endl;

    return 0;
}
